﻿namespace LMT.Db.OleDbClient
{
    using System.Data.Common;
    using System.Data.OleDb;

    /// <summary>
    /// 
    /// </summary>
    public sealed class OleDbProvider : DbProvider
    {
        /// <summary>
        /// 
        /// </summary>
        private static OleDbProvider sqlProvider;

        /// <summary>
        /// Gets the instance.
        /// </summary>
        public static OleDbProvider Instance
        {
            get
            {
                if (OleDbProvider.sqlProvider == null)
                {
                    OleDbProvider.sqlProvider = new OleDbProvider();
                }

                return OleDbProvider.sqlProvider;
            }
        }

        /// <summary>
        /// Prevents a default instance of the <see cref="SqlProvider"/> class from being created.
        /// </summary>
        private OleDbProvider()
        {
        }

        /// <summary>
        /// Initializes the oracle environment.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <exception cref="System.Data.OleDb.OleDbException"></exception>
        ///   
        /// <exception cref="System.InvalidOperatorException"></exception>
        public override void InitializeEnvironment(string connection)
        {
            base.InitializeEnvironment(connection);
            this.EntityParser = OleDbEntity.Instance;
        }

        /// <summary>
        /// Creates the connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <returns></returns>
        protected override DbConnection CreateConnection(string connection)
        {
            return new OleDbConnection(connection);
        }

        /// <summary>
        /// Creates the data adapter.
        /// </summary>
        /// <param name="oledbCom">The oledb COM.</param>
        /// <returns></returns>
        protected override DbDataAdapter CreateDataAdapter(DbCommand oledbCom)
        {
            return new OleDbDataAdapter(oledbCom as OleDbCommand);
        }
    }
}